home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1998 January / PC Answers Issue 49 Cover CD January 1998.iso / Apps / Director / DATA.Z / Animation Wizard.dir / 00008_Banners.ls < prev    next >
Encoding:
Text File  |  1997-05-10  |  7.7 KB  |  219 lines

  1. property ioFieldList, iFieldFocus, ioFIeldFocus, iCurrentMotionStyleIndex, iCurrentVisualStyleIndex, ikMotionRightToLeft, ikMotionLeftToRight, ikMotionUp, ikMotionDown, iFirstTime, iSaveSeconds, iSaveFPS, iSaveBaseline, iSaveDelayEnter, iSaveMark, iSaveCycles
  2.  
  3. on birth me
  4.   global goBannersText, goSeconds, goFPS, goBaseline, goDelayEnter, goCycles
  5.   set ioFieldList to [goBannersText, goSeconds, goFPS, goBaseline, goDelayEnter, goCycles]
  6.   set ikMotionRightToLeft to 1
  7.   set ikMotionLeftToRight to 2
  8.   set ikMotionUp to 3
  9.   set ikMotionDown to 4
  10.   set iCurrentMotionStyleIndex to ikMotionRightToLeft
  11.   set iCurrentVisualStyleIndex to 1
  12.   set iFieldFocus to 1
  13.   set iFirstTime to 1
  14.   return me
  15. end
  16.  
  17. on mInit me
  18.   global goSeconds, goFPS, goBaseline, goDelayEnter, goCycles, goBanners, goMarkFrame, goVisualStyles, goMotionStyles, goScoreMgr
  19.   mInit(goMarkFrame, 4)
  20.   if iFirstTime then
  21.     mSetValue(goSeconds, 5)
  22.     mSetValue(goFPS, 5)
  23.     set defaultBaseLine to integer(mGetStageHeight(goScoreMgr) / 2)
  24.     mSetValue(goBaseline, defaultBaseLine)
  25.     mSetValue(goDelayEnter, 0)
  26.     mSetValue(goCycles, 1)
  27.     mSetValue(goMarkFrame, 1)
  28.     set iFirstTime to 0
  29.   else
  30.     mSetValue(goSeconds, iSaveSeconds)
  31.     mSetValue(goFPS, iSaveFPS)
  32.     mSetValue(goBaseline, iSaveBaseline)
  33.     mSetValue(goDelayEnter, iSaveDelayEnter)
  34.     mSetValue(goCycles, iSaveCycles)
  35.     mSetValue(goMarkFrame, iSaveMark)
  36.   end if
  37.   set ioFIeldFocus to getAt(ioFieldList, iFieldFocus)
  38.   set goMotionStyles to 0
  39.   set goMotionStyles to birth(script "RadioButton", 26, 4, 0, iCurrentMotionStyleIndex)
  40.   if the machineType < 256 then
  41.     mInit(goVisualStyles, the number of member "BannersVisualStylesMac", iCurrentVisualStyleIndex, 8, 19)
  42.   else
  43.     mInit(goVisualStyles, the number of member "BannersVisualStylesPC", iCurrentVisualStyleIndex, 8, 19)
  44.   end if
  45.   set the keyDownScript to "mCheckKey(goBanners)"
  46. end
  47.  
  48. on mSetFieldFocus me, oWhom
  49.   set where to getOne(ioFieldList, oWhom)
  50.   if where = 0 then
  51.     alert("Internal error - mSetFieldFocus could not find object")
  52.     return 
  53.   end if
  54.   set iFieldFocus to where
  55.   set ioFIeldFocus to getAt(ioFieldList, iFieldFocus)
  56. end
  57.  
  58. on mCheckKey me
  59.   if the key = TAB then
  60.     set iFieldFocus to IncrMod(iFieldFocus, count(ioFieldList))
  61.     set ioFIeldFocus to getAt(ioFieldList, iFieldFocus)
  62.     pass()
  63.   else
  64.     if iFieldFocus = 1 then
  65.       pass()
  66.     else
  67.       if (offset(the key, "0123456789") > 0) or (the key = BACKSPACE) then
  68.         pass()
  69.       else
  70.         dontPassEvent()
  71.       end if
  72.     end if
  73.   end if
  74. end
  75.  
  76. on mSetNewMotionStyle me, theNewStyleIndex
  77.   set iCurrentMotionStyleIndex to theNewStyleIndex
  78. end
  79.  
  80. on mSetNewVisualStyle me, theNewStyleIndex
  81.   set iCurrentVisualStyleIndex to theNewStyleIndex
  82. end
  83.  
  84. on mValidate me
  85.   set lastFieldOKFlag to mValidate(ioFIeldFocus)
  86.   return lastFieldOKFlag
  87. end
  88.  
  89. on mCreate me
  90.   global goMarkFrame, goMotionStyles, goVisualStyles, goScoreMgr, goCastMgr, gDevelopmentFlag, gCastNumTextAsBitmap, goPlatform
  91.   if not mValidate(me) then
  92.     return 
  93.   end if
  94.   if field "BannersText" = EMPTY then
  95.     alert("Please enter some text for the banner.")
  96.     return 
  97.   end if
  98.   tell the stage
  99.     set theStageFrame to the frame
  100.   end tell
  101.   set castNumVisualStyle to mGetCastNum(goVisualStyles, iCurrentVisualStyleIndex)
  102.   set theVisualStyleName to the name of cast castNumVisualStyle
  103.   set theFont to word 2 of theVisualStyleName
  104.   set theSize to word 3 of theVisualStyleName
  105.   set theSeconds to integer(field "Seconds")
  106.   set fps to integer(field "FPS")
  107.   set nFrames to integer(theSeconds * fps)
  108.   set baseLine to integer(field "BaseLine")
  109.   set delayEnter to integer(field "DelayEnter")
  110.   set nCycles to integer(field "Cycles")
  111.   set markFirst to mGetValue(goMarkFrame)
  112.   set nTotalFrames to nFrames * nCycles
  113.   if not mInit(goScoreMgr, nTotalFrames, 1) then
  114.     return 
  115.   end if
  116.   set theCh to mGetNextSelectedChannel(goScoreMgr)
  117.   set theFrameNum to mGetStartFrame(goScoreMgr)
  118.   set castNumSource to mModifyRichTextCM(goCastMgr, the text of field "BannersText", theFont, theSize)
  119.   if castNumSource = 0 then
  120.     return 
  121.   end if
  122.   set the picture of member gCastNumTextAsBitmap to the picture of member castNumSource
  123.   set widthOfTextAsBitmap to the width of member gCastNumTextAsBitmap
  124.   set heightOfTextAsBitmap to the height of member castNumSource / the number of lines in the text of member castNumSource
  125.   if (iCurrentMotionStyleIndex = ikMotionRightToLeft) or (iCurrentMotionStyleIndex = ikMotionLeftToRight) then
  126.     set yStart to baseLine
  127.     set yEnd to baseLine
  128.     set yInc to 0
  129.     if iCurrentMotionStyleIndex = ikMotionRightToLeft then
  130.       set xStart to mGetStageRight(goScoreMgr) + 10
  131.       set xEnd to 0 - widthOfTextAsBitmap - 10
  132.       set xInc to float(xEnd - xStart) / float(nFrames)
  133.     else
  134.       set xStart to 0 - widthOfTextAsBitmap - 10
  135.       set xEnd to mGetStageRight(goScoreMgr) + 10
  136.       set xInc to float(xEnd - xStart) / float(nFrames)
  137.     end if
  138.   else
  139.     set xStart to (mGetStageWidth(goScoreMgr) / 2) - (widthOfTextAsBitmap / 2)
  140.     set xEnd to xStart
  141.     set xInc to 0
  142.     if iCurrentMotionStyleIndex = ikMotionUp then
  143.       set yStart to mGetStageHeight(goScoreMgr) + heightOfTextAsBitmap + 1
  144.       set yEnd to 0 - heightOfTextAsBitmap - 10
  145.       set yInc to float(yEnd - yStart) / float(nFrames)
  146.     else
  147.       set yStart to 0 - heightOfTextAsBitmap - 10
  148.       set yEnd to mGetStageHeight(goScoreMgr) + heightOfTextAsBitmap + 10
  149.       set yInc to float(yEnd - yStart) / float(nFrames)
  150.     end if
  151.   end if
  152.   set theForeColor to 255
  153.   set theBackColor to 0
  154.   set castNumTarget to mFindFreeCastRun(goCastMgr, 1, 1)
  155.   copyToClipBoard(member castNumSource)
  156.   tell the stage
  157.     pasteClipBoardInto(member castNumTarget)
  158.     set the name of member castNumTarget to "RichText" && string(the ticks)
  159.   end tell
  160.   set frameList to []
  161.   repeat with i = theFrameNum to theFrameNum + nTotalFrames - 1
  162.     add(frameList, [i])
  163.   end repeat
  164.   if markFirst then
  165.     set firstFrame to getAt(frameList, 1)
  166.     set theLabel to "AW.Banner." & word 1 of the text of field "BannersText" & " " & mGetGeneratedScoreSelection(goScoreMgr)
  167.     add(firstFrame, [#label, theLabel])
  168.     setAt(frameList, 1, firstFrame)
  169.   end if
  170.   set relFrameCount to 1
  171.   repeat with thisCycle = 1 to nCycles
  172.     set firstFrame to getAt(frameList, relFrameCount)
  173.     set secondFrame to getAt(frameList, relFrameCount + 1)
  174.     if delayEnter > 0 then
  175.       add(firstFrame, [#tempo, -delayEnter])
  176.       add(secondFrame, [#tempo, fps])
  177.     else
  178.       add(firstFrame, [#tempo, fps])
  179.       add(secondFrame, [#tempo, 0])
  180.     end if
  181.     setAt(frameList, relFrameCount, firstFrame)
  182.     setAt(frameList, relFrameCount + 1, secondFrame)
  183.     set xLoc to xStart
  184.     set yLoc to yStart
  185.     repeat with thisFrame = 1 to nFrames
  186.       set xLoc to integer(xLoc + 0.49000000000000005)
  187.       set yLoc to integer(yLoc + 0.49000000000000005)
  188.       set currentFrame to getAt(frameList, relFrameCount)
  189.       add(currentFrame, [#sprite, theCh, castNumTarget, theForeColor, theBackColor, xLoc, yLoc, 0, 0])
  190.       setAt(frameList, relFrameCount, currentFrame)
  191.       set theFrameNum to theFrameNum + 1
  192.       set relFrameCount to relFrameCount + 1
  193.       set xLoc to xLoc + xInc
  194.       set yLoc to yLoc + yInc
  195.     end repeat
  196.   end repeat
  197.   mWriteFrame(goScoreMgr, frameList)
  198.   set labelName to "Banners" & goPlatform
  199.   go(label(labelName) + 2)
  200.   if not gDevelopmentFlag then
  201.     tell the stage
  202.       go(theStageFrame)
  203.     end tell
  204.   end if
  205.   mClean(goScoreMgr)
  206. end
  207.  
  208. on mCleanUp me
  209.   global goMotionStyles, goSeconds, goFPS, goBaseline, goDelayEnter, goCycles, goMarkFrame
  210.   mCleanUp(goMotionStyles)
  211.   set iSaveSeconds to mGetValue(goSeconds)
  212.   set iSaveFPS to mGetValue(goFPS)
  213.   set iSaveBaseline to mGetValue(goBaseline)
  214.   set iSaveDelayEnter to mGetValue(goDelayEnter)
  215.   set iSaveCycles to mGetValue(goCycles)
  216.   set iSaveMark to mGetValue(goMarkFrame)
  217.   mCleanUp(goMarkFrame)
  218. end
  219.